class Fragment < ActiveRecord::Base
  
  belongs_to :job
  validates_associated :job

  validates_presence_of Fragment.column_names - ["id", "job_id", "created_at", "updated_at", "selected", "rr"]
  validates_inclusion_of :selected, :rr, :in => [true, false]
  validates_numericality_of :bb, :bbh, :bbs, :abb, :sbb, :only_integer => true
  validates_numericality_of :fragment, :only_integer => true, :greater_than_or_equal_to => 0
  validates_numericality_of :peaknum, :rank, :only_integer => true, :greater_than_or_equal_to => 1
  validates_numericality_of :peakmass, :mass, :greater_than_or_equal_to => 0
  validates_inclusion_of :score, :in => (0.0 .. 1.0)
  validates_format_of :atombits, :with => /[01]+/

  named_scope :selected,  { :conditions => { :selected => true }}

  # Returns True if current fragment isomorphic with specified fragment,
  # otherwise false.
  def isomorphic_to?(fragment)
    self.job_id == fragment.job_id && self.rank == fragment.rank && self.mass == fragment.mass
  end
end
